package main

import (
	"weiboxs.com/new_h_glasses/initial"
	_ "weiboxs.com/new_h_glasses/initial"
	_ "weiboxs.com/new_h_glasses/routers"

	"fmt"
	beego "github.com/beego/beego/v2/adapter"
	"github.com/beego/beego/v2/adapter/logs"
	"github.com/kardianos/service"
	"os"
)

type program struct{}

func (p *program) Start(s service.Service) error {
	go p.run()
	go initial.GetUpdData()
	return nil
}

func (p *program) run() {
	beego.SetViewsPath(beego.AppPath + "/views")
	beego.SetStaticPath("/static", beego.AppPath+"\\static")
	beego.Run()
}

func (p *program) Stop(s service.Service) error {
	return nil
}

func main() {

	svcConfig := &service.Config{
		Name:        fmt.Sprintf("%s%s", beego.AppConfig.String("service::name"), beego.AppConfig.String("httpport")), //服务显示名称
		DisplayName: fmt.Sprintf("%s%s", beego.AppConfig.String("service::name"), beego.AppConfig.String("httpport")), //服务名称
		Description: beego.AppConfig.String("service::description"),                                                   //服务描述
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		logs.Error(err)
	}

	if err != nil {
		logs.Error(err)
	}

	if len(os.Args) > 1 { //设置控制动作
		err = service.Control(s, os.Args[1])
		if err != nil {
			logs.Error(err)
		}
		return
	}

	err = s.Run()
	if err != nil {
		logs.Error(err)
	}

}
